﻿<template id="layout_page_dialog_template">
    <el-dialog v-model="visible" :title="title" :width="width" :fullscreen="fullscreen" :destroy-on-close="true" :close-on-click-modal="false" :close-on-press-escape="false" draggable v-on:close="closed" :show-close="allowClose">
        <el-divider class="layout-page-form-top-border"></el-divider>
        <div class="layout-page-component">
            <component :is="component"></component>
        </div>
        <template v-if="footer" #footer>
            <el-button v-if="allowClose" v-on:click="close">取消</el-button>
            <el-button v-if="submit" type="primary" v-on:click="submit">确定</el-button>
        </template>
    </el-dialog>
</template>
<script type="text/javascript">
    var layout_page_dialog = {
        template: "#layout_page_dialog_template",
        data() {
            return {
                loading: false,
                component: null,
                visible: false,
                title: null,
                width: 0,
                footer: true,
                fullscreen: false,
                submit: null,
                allowClose: true
            }
        },
        methods: {
            loadDialog(title, src) {
                var that = this;
                if (src) {
                    that.title = title;
                    that.width = 500;
                    that.visible = true;
                    that.$nextTick(() => {
                        app.func.ajax({
                            url: src,
                            dataType: "text",
                            target: ".el-dialog",
                            cache: false,
                            success(result) {
                                try {
                                    var htmlBox = $(".layout-page-html");
                                    var qIndex = src.indexOf('?');
                                    if (qIndex != -1) { src = src.substring(0, qIndex); }
                                    var compName = src.substring(1).replace(/\//g, "_");
                                    htmlBox.html(result);
                                    that.$nextTick(() => {
                                        that.component = Vue.markRaw(eval(compName));
                                        that.$nextTick(() => {
                                            htmlBox.empty();
                                            eval(`${compName}=null`);
                                        });
                                    });
                                }
                                catch (err) {
                                    app.func.error("页面加载错误，请检查地址是否正确");
                                    console.error(err);
                                }
                            }
                        });
                    });
                }
            },
            close() {
                this.visible = false;
            },
            closed() {
                this.title = null;
                this.width = 0;
                this.footer = true;
                this.fullscreen = false;
                this.submit = null;
                this.component = null;
            }
        },
        mounted() { }
    };
</script>